import loadRequest
import weakref

class GraphicClientRequest(loadRequest.PrioritizedLoadRequest):
    __guid__ = 'loadRequest.GraphicClientRequest'

    def __init__(self, graphicClient, graphicID):
        self.owner = None
        self.graphicClient = graphicClient
        self.graphicID = graphicID
        self.components = weakref.WeakKeyDictionary()



    def GetName(self):
        modelPath = self.graphicClient.GetModelFilePath(self.graphicID)
        return ('graphicID %d - %s' % (self.graphicID, modelPath))



    def GetPriority(self):
        return sum(self.components.itervalues())



    def IsEmpty(self):
        return (not bool(self.components))



    def Process(self):
        for obj in self.components.iterkeys():
            self.graphicClient._LoadComponent(obj)




    def AddComponent(self, obj):
        self.components[obj] = 0



    def RemoveComponent(self, obj):
        if (obj in self.components):
            del self.components[obj]



    def SetPriority(self, obj, priority):
        self.components[obj] = priority




